package com.gtq.uhome.controller;

import com.gtq.uhome.result.Result;
import com.gtq.uhome.service.AuditManagementService;
import com.gtq.uhome.vo.AuditManagement;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@Controller
@RequestMapping(value = "/auditManagement")
@CrossOrigin
@Api(tags = "站点后台——待审核列表//更改——何凡")
public class AuditManagementController {

    @Resource
    private AuditManagementService auditManagementService;

    /**
     * 待审核列表，获取全部数据
     * @return
     */
    @GetMapping
    @ResponseBody
    @ApiOperation(value = "待审核列表，获取全部数据")
    public Result<List<AuditManagement>> findByAll(){
        List<AuditManagement> byAll = auditManagementService.findByAll();
        return Result.ok(byAll);
    }

    /**
     * 待审核列表，模糊查询，按条件查询
     * @param auditManagement
     * @return
     */
    @PostMapping
    @ResponseBody
    @ApiOperation(value = "待审核列表，模糊查询，按条件查询")
    public Result<List<AuditManagement>> findBy(@RequestBody AuditManagement auditManagement ){
        List<AuditManagement> byAll = auditManagementService.findBy(auditManagement);
        return Result.ok(byAll);
    }

    /**
     * 待审核列表，批量删除
     * @param auditManagement
     * @return
     */
    @PutMapping
    @ResponseBody
    @ApiModelProperty(value = "待审核列表，批量删除")
    public Result deleteOrder(@RequestBody List<AuditManagement> auditManagement ){
        System.out.println(auditManagement);
        Boolean aBoolean = auditManagementService.deleteOrder(auditManagement);
        if (aBoolean){
            return Result.ok("删除成功");
        }
        return Result.failed("删除失败");
    }
}
